package com.buy.utile;

import java.util.Scanner;

public class ComputeUtil {


    public static Integer computeFruit(Scanner scanner,String name,Integer unitPrice, Integer discount){

        System.out.println("请输入购买"+name+"多少斤：");
        Integer quantity = scanner.nextInt(); // 读取用户输入的一行文本
        if(quantity<0){
            System.out.println("购买的水果斤数不能为负数");
            quantity = scanner.nextInt(); // 读取用户输入的一行文本
        }
        Integer result = 0;
        result  = unitPrice * quantity;
        if(discount>0){
            result = (result*discount)/100;
        }

        return result;
    }

}
